package com.etc.service.impl;/*
 * 文件名：com.etc.service.impl
 * 描述：
 * 作者：袁祥辉
 * 时间：2019/5/27 9:19
 */

import com.etc.dao.GoodsPictureDao;
import com.etc.entity.GoodsPicture;
import com.etc.service.GoodsPictureService;
import com.etc.utils.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class GoodsPictureServiceImpl implements GoodsPictureService {

    @Autowired
    private GoodsPictureDao goodsPictureDao;

    @Override
    public PageData<GoodsPicture> getGoodsPictureByPage(int page, int pageSize, String content) {
        Integer start = (page-1)*pageSize;
        //查询核实数据
        List<GoodsPicture> data = goodsPictureDao.selectGoodsPictureByPage(start,pageSize,content);
        for (GoodsPicture goodsPicture:data) {
            goodsPicture.setPictureurl("<img src="+goodsPicture.getPictureurl()+">");
        }
        
        Integer count = goodsPictureDao.selectCount(content);
        PageData<GoodsPicture> pd = new PageData<>(data,count,pageSize,page);

        return pd;
    }

    @Override
    public boolean deleteGoodsPicturetById(Integer pictureid) {
        return goodsPictureDao.deleteByPrimaryKey(pictureid)>0;
    }

    @Override
    public List<GoodsPicture> listAllGoodsPicture() {
        return goodsPictureDao.selectAllGoodspicture();
    }

    @Override
    public boolean addGoodsPicture(GoodsPicture goodsPicture) {
        return goodsPictureDao.insert(goodsPicture)>0;
    }

    @Override
    public boolean updateGoodsPicture(GoodsPicture goodsPicture) {
        return goodsPictureDao.updateByPrimaryKey(goodsPicture)>0;
    }


    @Override
    public Boolean updateByPictureid ( Integer pictureid, String pictureurl ) {
        return goodsPictureDao.updateByPictureid(pictureid,pictureurl)>0;
    }

    @Override
    public Boolean delGoodsPictureByGid (Integer goodsid) {
        return goodsPictureDao.delGoodsPictureByGid(goodsid)>0;
    }

    @Override
    public List<GoodsPicture> listGoodspictureByGid ( Integer goodsid ) {
        return goodsPictureDao.listGoodspictureByGid(goodsid);
    }

    @Override
    public GoodsPicture getGoodspictureByGid ( Integer goodsid ) {
        return goodsPictureDao.getGoodspictureByGid(goodsid);
    }
}
